package mearth;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import processing.core.PApplet;
import processing.core.PImage;


public class CellSpatialImage1 extends PApplet {

	PImage map;

	GridImage gimage;

	public void setup(){
		size(1280,1024, JAVA2D);
		PImage img = loadImage("sea002.png");

//		gimage = new GridImage(this, "sea002.png");
		gimage = new GridImage(this, img);

//		saveGridImage(gimage, "test");
		
		
		noSmooth();
		background(0);

		pushMatrix();
		//		translate(-1280,-1240);
		scale(0.25f);
		noStroke();
//		gimage.display(this);

		gimage.display(this, 1500,1500,500,400);
		popMatrix();
		stats();

		
		//		exit();

	}

	public void saveGridImage(GridImage pgimage, String fname){
		File file = new File(fname);
		try {
			FileOutputStream fos = new FileOutputStream(file);
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject( pgimage);
			fos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


	public void stats(){
		System.out.println("Nbr nodes parent = " + GridNode.nbrParents);
		System.out.println("Nbr nodes leaves = " + GridNode.nbrLeaves);
		int memParents = GridNode.nbrParents * 21;
		int memLeaves = GridNode.nbrLeaves * 5;
		int mem = memParents + memLeaves;
		System.out.println("Memory used:");
		System.out.println("Parents\t" + memParents);
		System.out.println("Leaves\t" + memLeaves);
		System.out.println("Total\t" + mem);
		System.out.println();
		float pcDisplayed = (100.0f * GridNode.nbrDisplayed)/ GridNode.nbrLeaves;
		System.out.println("Number traversed for display " + GridNode.nbrDisplayed + "  (" + pcDisplayed + "%)");
	}

}

